package day09API.stream;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author DBX
 * @effect 创建日志文件
 * @date 2021/8/28 0028 - 16:39
 */
public class Logger {
    public  static void log(String s) {
        PrintStream ps = null;
        try {
            ps = new PrintStream(new FileOutputStream("File/log.txt",true));
//            改变输出方向
            System.setOut(ps);
            Date date = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String time = sdf.format(date);
            System.out.println(time+" :"+s);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }finally{
            if (ps != null) {
                ps.close();
            }
        }
    }
}
class Test{
    public static void main(String[] args) {
        Logger.log("今天也要元气满满哦");
        Logger.log("????");
        Logger.log("系统垃圾过多，建议回收");
    }
}
